// ksun48
#include <bits/stdc++.h>
using namespace std;

using ll = int64_t;

int main(){
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    int N; cin >> N;
    string S; cin >> S;
    vector<int> A(N);
    for(int i = 0; i < N; ++i) A[i] = S[i] == '0';
    vector<int> cnt(2);
    int cur = 0;
    for(int i = 0; i < N; ++i){
        cnt[cur]++;
        cur ^= A[i];
    }
    cnt[cur]++;
    ll ans = 0;
    ans = ll(cnt[0])*(cnt[0]-1)/2 + ll(cnt[1])*(cnt[1]-1)/2;
    
    cout << ans << '\n';
    return 0;
}
